const mongoClient = require('./models/mongo/client');
// const redis = require('./models/redis');
const amqp = require('./models/amqp');
const { MessagePublisher } = require('./models/amqp/pub-sub/publisher');

/**
 * 服务类
 */
class Server {
  constructor() {
    // 连接数据库
    mongoClient.connect().then(() => {}).catch(() => {});
    // 消息队列
    amqp.checkConnection()
      .then(() => {
        // 创建websocket publisher单例
        MessagePublisher.createWebsocketMessageBus().then(() => {}).catch(() => {});
        amqp.listening();
      })
      .catch(() => {});
  }
}

/**
 * 创建子进程
 */
function createServer() {
  return new Server();
}

/**
 * Export model definition object.
 */
module.exports = createServer;
